﻿using System;
using System.ComponentModel;
using System.Threading;
using System.Workflow.Activities;
using System.Workflow.ComponentModel;


namespace WorkflowLibrary
{
    
	public partial class DisplayPageActivity: SequenceActivity
    {
        #region events and event handlers

        public delegate void PageShownEventHandler(object sender,
            PageShownEventArgs e);
        private event PageShownEventHandler pageShownEvent;
        public event PageShownEventHandler PageShown
        {
            add
            {
                pageShownEvent += value;
            }
            remove
            {
                pageShownEvent -= value;
            }
        }

        #endregion

        #region Construction

        public DisplayPageActivity()
		{
			InitializeComponent();
        }

        #endregion

        #region Dependency properties

        

        
        

        public static DependencyProperty PageGuidProperty =
                    DependencyProperty.Register("PageGuid",
                    typeof(System.Guid),
                    typeof(DisplayPageActivity));

        [DesignerSerializationVisibilityAttribute
            (DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [DescriptionAttribute("Guid of form to be shown")]
        [CategoryAttribute("ShowForm Property")]
        public System.Guid PageGuid
        {
            get
            {
                return ((System.Guid)(base.GetValue(DisplayPageActivity.PageGuidProperty)));
            }
            set
            {
                base.SetValue(DisplayPageActivity.PageGuidProperty, value);
            }
        }

        public static DependencyProperty WorkflowIdProperty =
                    DependencyProperty.Register("WorkflowId",
                    typeof(System.Guid),
                    typeof(DisplayPageActivity));

        [DesignerSerializationVisibilityAttribute
            (DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [DescriptionAttribute("Guid of activity's workflow")]
        [CategoryAttribute("ShowForm Property")]
        public System.Guid WorkflowId
        {
            get
            {
                return ((System.Guid)(base.GetValue(DisplayPageActivity.WorkflowIdProperty)));
            }
            set
            {
                base.SetValue(DisplayPageActivity.WorkflowIdProperty, value);
            }
        }

        public static DependencyProperty StructureIdProperty =
                    DependencyProperty.Register("StructureId",
                    typeof(System.Guid),
                    typeof(DisplayPageActivity));

        [DesignerSerializationVisibilityAttribute
            (DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [DescriptionAttribute("Guid of activity's workflow")]
        [CategoryAttribute("ShowForm Property")]
        public System.Guid StructureId
        {
            get
            {
                return ((System.Guid)(base.GetValue(DisplayPageActivity.StructureIdProperty)));
            }
            set
            {
                base.SetValue(DisplayPageActivity.StructureIdProperty, value);
            }
        }

        #endregion

        private void codeActivity1_ExecuteCode(object sender, EventArgs e)
        {
            Thread.Sleep(2000);
            if (pageShownEvent != null)
            {
                pageShownEvent(null, new PageShownEventArgs(PageGuid, WorkflowId, StructureId));
            }
        }

    }


    public class PageShownEventArgs
    {
        private Guid formGuid;
        private Guid workflowInstanceId;
        private Guid structureId;


        public PageShownEventArgs(Guid _fGuid, Guid _wGuid, Guid _sGuid)
        {
            this.formGuid = _fGuid;
            this.workflowInstanceId = _wGuid;
            this.structureId = _sGuid;
        }

        public Guid FormGuid
        {
            get { return this.formGuid; }
        }

        public Guid WorkflowInstanceId
        {
            get { return this.workflowInstanceId; }
        }

        public Guid StructureId
        {
            get { return this.structureId; }
        }

    }
}
